/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.ArrayList;

/**
 *
 * @author ldtung_it
 */
public class TableRender extends DefaultTableCellRenderer implements TableCellRenderer {

    private final Color backGround;
    
    
    ArrayList<CellTable> cells;

    public TableRender(Color backGround, ArrayList<CellTable> cells) {
        this.backGround = backGround;
        this.cells = cells;
    }

    

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        //throw new UnsupportedOperationException("Not supported yet.");
        JLabel template = (JLabel)super.getTableCellRendererComponent( table, value,
isSelected, hasFocus, row, column );
        
        for (CellTable cell : cells){
            if (row == cell.getRow() && column == cell.getColumn()){
                this.setBackground(backGround);

                break;
            } else {
                this.setBackground(Color.WHITE);
            }
        }
        template.setVerticalAlignment(JLabel.TOP);
        
        return template;
    }
}
